﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class CheckCodeImg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack) 
		{
			Int32 charCount;
			String cCount = Request.QueryString["cc"];
			if (!(cCount != null && Int32.TryParse(cCount, out charCount) && 
					charCount > 0 && charCount < 8))
				charCount = 4;
			Utility.CheckCode cc = new Utility.CheckCode(60, charCount);
			SessionMan.SaveCheckCode(cc.GetCodeString());
			MemoryStream ms = new MemoryStream();
			cc.GetCodeImage().Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
			Response.ClearContent();
			Response.ContentType = "image/gif";
			Response.BinaryWrite(ms.ToArray());
			Response.End(); 
		}
    }
}
